package com.cumt.threeway.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cumt.threeway.R;
import com.cumt.threeway.table.GonglueEntity;

import java.util.List;

/**
 * Created by 胡晶晶 on 2016/5/22.
 */
public class StrategyAdapter extends BaseAdapter {

    private List<GonglueEntity> mList;
    private Context mContext;

    public StrategyAdapter(List<GonglueEntity> list, Context context) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.stategy_item, null);
            viewHolder = new ViewHolder();
            viewHolder.mIvIcon = (ImageView) convertView.findViewById(R.id.iv_icon);
            viewHolder.mTvTitle = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.mTvDate = (TextView) convertView.findViewById(R.id.tv_date);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        GonglueEntity activities = mList.get(position);
        viewHolder.mIvIcon.setImageResource(R.drawable.huodonggongnue);
        viewHolder.mTvTitle.setText(activities.getTitle());
        viewHolder.mTvDate.setText(activities.getTime());
        return convertView;
    }

    class ViewHolder {
        private ImageView mIvIcon;
        private TextView mTvTitle;
        private TextView mTvDate;
    }

}
